java当中JDBC当中请给出一个Oracle DataSource and SingleTon例子

[学习笔记]

6.Oracle DataSource and SingleTon: 

import oracle.jdbc.pool.OracleDataSource;
import java.sql.Connection;
import java.sql.*;

public class OracleSingletonDataSource {
  static private OracleDataSource ods;
  private OracleSingletonDataSource() {
    try{
        ods = new OracleDataSource();
        ods.setURL("jdbc:oracle:thin:@localhost:1521:qixy");
        ods.setUser("scott");
        ods.setPassword("tiger");
            }catch(Exception e){
            e.printStackTrace();
            }
  }
  public static Connection getConnection() throws Exception {
    if (ods==null)
       {
           new OracleSingletonDataSource();
          // ods.getConnection();

      }
      Connection con =null;
      try {
          con = ods.getConnection();
      } catch (SQLException ex) {
        ex.printStackTrace();
      }
       return  con;
      }

}

更多内容请见原文,文章转载自原文: https://blog.csdn.net/qq_43650923/article/details/100654724

 

posted @ 2019-10-03 14:47  海中一神兽  阅读(459)  评论(0编辑  收藏  举报